package com.gtgj.widget.util;

import com.gtgj.widget.calender.GTLunarCalendarV2;
import com.gtgj.widget.calender.LunarCalendar;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;


public class DateUtils extends LibDateUtils {
    public static final String[] WEEK_CHS = {"", "周日", "周一", "周二", "周三", "周四", "周五", "周六"};
    public static final String[] WEEK_CHS2 = {"", "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    public static final int WEEKDAY_TYPE_TWO_WORDS = 1;
    public static final int WEEKDAY_TYPE_THREE_WORDS = 2;
    public static final long LONG_TIME_OF_A_DAY = 1000 * 60 * 60 * 24;

    /*
     * 比较俩个日期，主要是未了消除格式差异
     */
    public static int compare(String date1, String date2) {
        String d1 = convertDateToStandardFormat(date1);
        String d2 = convertDateToStandardFormat(date2);
        return d1.compareTo(d2);
    }


    /*
     * 获取制定时间后后得多少天
     */
    public static String getYMDStringAfterTime(long time, int days) {
        try {
            time = time + days * 24 * 60 * 60 * 1000l;
            Date date = new Date();
            date.setTime(time);
            return yyyy_MM_dd().format(date);
        } catch (Exception e) {
            return "";
        }
    }

    public static ArrayList<Date> getDaysYMDStringList(boolean hasDash, String arrs) {
        ArrayList<Date> arrayList = new ArrayList<>();
        String[] sa = null;
        if (!TextUtils.isEmpty(arrs)) {
            sa = arrs.split(",");
        }
        if (sa != null && sa.length > 0) {
            try {
                for (int i = 0; i < sa.length; i++) {
                    if (hasDash) {
                        Date date = yyyy_MM_dd().parse(sa[i]);
                        arrayList.add(date);
                    } else {
                        arrayList.add(yyyyMMdd().parse(sa[i]));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return arrayList;
    }

    /*
     * 获取当天时间
     */
    public static String getTodayYMDString(boolean hasDash) {
        if (hasDash) {
            return yyyy_MM_dd().format(new Date());
        }
        return yyyyMMdd().format(new Date());
    }

    public static String getNowMDString() {
        return HH_mm().format(new Date());
    }

    public static String getTodayYMString(boolean hasDash) {
        if (hasDash) {
            return yyyy_MM().format(new Date());
        }
        return yyyyMM().format(new Date());
    }

    /*
     * 获取20110101/2010-01-01时间格式
     */
    public static String getYMDString(int year, int month, int day, boolean hasDash) {
        Calendar c = Calendar.getInstance();
        c.set(year, month, day);
        if (hasDash) {
            return yyyy_MM_dd().format(c.getTime());
        }
        return yyyyMMdd().format(c.getTime());
    }

    /*
     * 将2011-11-22转成2011年11月22日
     */
    public static String getYMDWithCString(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String ymd = yyyCMMCddC().format(d);
            return ymd;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 将2011-11-22转成11月22日
     */
    public static String getMMDDWithCString(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String md = MMddC().format(d);
            return md;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 确保格式为yyyy-MM-dd
     */
    public static String formatYMDStringWithHash(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return yyyy_MM_dd().format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 将11-22转成11月22日
     */
    public static String getMDWithCString(String md) {
        try {
            md = md.replace("-", "");
            Date d = MMdd().parse(md);
            String mdc = Md().format(d);
            return mdc;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return md;
    }

    /*
     * 将yyy-MM-dd格式的日期字符串转成"9月11日 星期三"的格式
     */
    public static String getMDWString(String date) {
        return getMDWString(date, false);
    }

    /*
     * 将yyy-MM-dd/yyyyMMdd格式的日期字符串转成"9月11日 星期三/今天(明天)"的格式
     */
    public static String getMDWString(String date, boolean isRelative) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date dateO = yyyyMMdd().parse(sDate);
            String md = Md().format(dateO);
            String week = getDayInWeekByType(date, WEEKDAY_TYPE_THREE_WORDS, isRelative);
            return md + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 将yyy-MM-dd格式的日期字符串转成"2011年9月11日 星期三"的格式
     */
    public static String getYMDWString(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String ymd = yyyCMMCddC().format(d);
            String week = getDayInWeek(sDate);
            return ymd + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 将yyy-MM-dd格式的日期字符串转成"2011-09-11 星期三"的格式
     */
    public static String getYMDWString2(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String ymd = yyyy_MM_dd().format(d);
            String week = getDayInWeek(sDate);
            return ymd + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 获取间隔以后的日期
     */
    public static String getYMDStringByGap(String date, int gapType, int gap) {
        try {
            boolean hasDash = date.length() == 8 ? false : true;
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            c.add(gapType, gap);
            return hasDash ? yyyy_MM_dd().format(c.getTime()) : yyyyMMdd().format(c.getTime());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    public static int[] getYMD(String date) {
        try {
            date = date.replaceAll("-", "");
            int[] ymd = new int[3];
            ymd[0] = TypeUtils.StringToInt(date.substring(0, 4));
            ymd[1] = TypeUtils.StringToInt(date.substring(4, 6)) - 1;
            ymd[2] = TypeUtils.StringToInt(date.substring(6, 8));
            return ymd;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取一个指定日期与当天之间间隔的天数 返回0表示一样 返回负数表示在当天之前多少天 返回正数表示在当天之后多少天
     */
    public static int getDaysBetweenTodayAndDate(String date) {
        int daysBetween = 0;
        try {
            if (TextUtils.isEmpty(date)) {
                return daysBetween;
            }
            String sDate = convertDateToStandardFormat(date);
            Date comparedDate = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(comparedDate);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);

            Calendar today = Calendar.getInstance();
            today.set(Calendar.HOUR_OF_DAY, 0);
            today.set(Calendar.MINUTE, 0);
            today.set(Calendar.SECOND, 0);
            today.set(Calendar.MILLISECOND, 0);
            daysBetween = (int) ((c.getTime().getTime() - today.getTime().getTime()) / LONG_TIME_OF_A_DAY);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return daysBetween;
    }

    /**
     * 获取一个指定日期与当天之间间隔的天数 返回0表示一样 返回负数表示在当天之前多少天 返回正数表示在当天之后多少天
     */
    public static int getDaysBetweenTimeAndDate(String date, long currentTime) {
        int daysBetween = 0;
        try {
            if (TextUtils.isEmpty(date)) {
                return daysBetween;
            }
            String sDate = convertDateToStandardFormat(date);
            Date comparedDate = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(comparedDate);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);

            Calendar today = Calendar.getInstance();
            today.setTime(new Date(currentTime));
            today.set(Calendar.HOUR_OF_DAY, 0);
            today.set(Calendar.MINUTE, 0);
            today.set(Calendar.SECOND, 0);
            today.set(Calendar.MILLISECOND, 0);
            daysBetween = (int) ((c.getTime().getTime() - today.getTime().getTime()) / LONG_TIME_OF_A_DAY);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return daysBetween;
    }

    /*
     * 获取{"今天/周一", "02", "02"}
     */
    public static String[] getDayInWeekDayMonth(int year, int month, int day) {
        String[] dateInSplite = new String[3]; // 星期、几号、月份
        Calendar c = Calendar.getInstance();
        String today = yyyyMMdd().format(c.getTime());
        c.add(Calendar.DATE, 1);
        String tommorrow = yyyyMMdd().format(c.getTime());
        c.add(Calendar.DATE, 1);
        String theDayAfterTommorrow = yyyyMMdd().format(c.getTime());
        c.set(year, month, day);
        dateInSplite[0] = getDayInWeek(yyyyMMdd().format(c.getTime()));
        if (today.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "今天";
        } else if (tommorrow.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "明天";
        } else if (theDayAfterTommorrow.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "后天";
        } else {
            String holiday = LunarCalendar.getHoliday(month + 1, day);
            if (!TextUtils.isEmpty(holiday)) {
                dateInSplite[0] = holiday;
            }
            String jieqi = LunarCalendar.getSoralTerm(year, month + 1, day);
            if (!TextUtils.isEmpty(jieqi)) {
                dateInSplite[0] = jieqi;
            }
        }
        dateInSplite[1] = c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + c.get(Calendar.DAY_OF_MONTH) : "" + c.get(Calendar.DAY_OF_MONTH);
        dateInSplite[2] = (c.get(Calendar.MONTH) + 1) < 10 ? "0" + (c.get(Calendar.MONTH) + 1) : "" + (c.get(Calendar.MONTH) + 1);

        return dateInSplite;
    }

    /*
     * 将"20110927/2011-09-27"格式的日期转换为星期
     */
    public static String getDayInWeek(String date) {
        return getDayInWeekByType(date, WEEKDAY_TYPE_THREE_WORDS, false);
    }

    /*
     * 将"20110927/2011-09-27"格式的日期转换为星期/周
     */
    public static String getDayInWeekByType(String date, int type, boolean isRelative) {
        if (TextUtils.isEmpty(date) || (date.length() != 8 && date.length() != 10)) {
            return "";
        }
        String day = "";
        int y, m, d;
        if (date.length() == 8) {
            y = TypeUtils.StringToInt(date.substring(0, 4));
            m = TypeUtils.StringToInt(date.substring(4, 6));
            d = TypeUtils.StringToInt(date.substring(6, 8));
        } else {
            y = TypeUtils.StringToInt(date.substring(0, 4));
            m = TypeUtils.StringToInt(date.substring(5, 7));
            d = TypeUtils.StringToInt(date.substring(8, 10));
        }
        Calendar c = Calendar.getInstance();
        c.set(y, m - 1, d);
        int dw = c.get(Calendar.DAY_OF_WEEK);
        if (type == WEEKDAY_TYPE_THREE_WORDS) {
            day = WEEK_CHS2[dw];
        } else {
            day = WEEK_CHS[dw];
        }
        if (isRelative) {
            Calendar c1 = Calendar.getInstance();
            String today = yyyyMMdd().format(c1.getTime());
            c1.add(Calendar.DATE, 1);
            String tommorrow = yyyyMMdd().format(c1.getTime());
            c1.add(Calendar.DATE, 1);
            String theDayAfterTommorrow = yyyyMMdd().format(c1.getTime());
            String sDate = convertDateToStandardFormat(date);
            if (sDate.equals(today)) {
                day = "今天";
            } else if (sDate.equals(tommorrow)) {
                day = "明天";
            } else if (sDate.equals(theDayAfterTommorrow)) {
                day = "后天";
            }
        }
        return day;
    }

    /*
     * 返回时，分数组。可以解析以分为单位以及00:00格式的时间
     */
    public static int[] getMinSecWithString(String str) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        int[] result = new int[2];
        if (str.contains(":")) {
            String[] sArray = str.split(":");
            if (sArray.length > 1) {
                result[0] = TypeUtils.StringToInt(sArray[0]);
                result[1] = TypeUtils.StringToInt(sArray[1]);
            }
        } else {
            int all = TypeUtils.StringToInt(str);
            result[0] = all / 60;
            result[1] = all % 60;
        }
        return result;
    }

    /*
     * 将122秒数转换成02:02的格式
     */
    public static String secsToMinSecFormat(int seconds) {
        double min = seconds / 60;
        double sec = seconds % 60;
        DecimalFormat nf = new DecimalFormat("#00");
        return nf.format(min) + ":" + nf.format(sec);
    }

    /*
     * 将123123秒转换成x天x小时x分
     */
    public static String secsToDHMFormat(long seconds, boolean onlyDisplayLongIfPassed) {
        long day = seconds / (60 * 60 * 24);

        StringBuffer sb = new StringBuffer();
        if (day > 0) {
            sb.append(String.format("%d天", day));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }

        seconds = seconds % (60 * 60 * 24);
        long hour = seconds / (60 * 60);
        if (hour > 0) {
            sb.append(String.format("%d小时", hour));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }

        seconds = seconds % (60 * 60);
        long min = seconds / 60;
        if (min > 0) {
            sb.append(String.format("%d分钟", min));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }
        return sb.toString();
    }

    /*
     * 将123123秒转换成x天x小时x分
     */
    public static String MinsToDHMFormat(long mins, boolean onlyDisplayLongIfPassed) {
        long day = mins / (60 * 24);

        StringBuffer sb = new StringBuffer();
        if (day > 0) {
            sb.append(String.format("%d天", day));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }

        mins = mins % (60 * 24);
        long hour = mins / 60;
        if (hour > 0) {
            sb.append(String.format("%d小时", hour));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }

        mins = mins % 60;
        long min = mins;
        if (min > 0) {
            sb.append(String.format("%d分钟", min));
            if (onlyDisplayLongIfPassed) {
                return sb.toString();
            }
        }
        return sb.toString();
    }

    /*
     * 将123123秒转换成x天x小时x分, 如果超过一天则只显示x天
     */
    public static String secsToDHMForma4bus(long seconds, long departTimeInMillisons, boolean onlyDisplayLongIfPassed) {
        long day = seconds / (60 * 60 * 24);

        StringBuffer sb = new StringBuffer();
        if (day > 0) {
            //e.g fn round()
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.add(Calendar.DAY_OF_MONTH, 1);
            long TomorrowBeginTimeInMillis = calendar.getTimeInMillis();
            long diff = departTimeInMillisons - TomorrowBeginTimeInMillis;
            long dayCount = diff / (24 * 60 * 60 * 1000);
            if (diff > 0) {
                sb.append(String.format("%d天", dayCount + 1));
            }
        } else {
            seconds = seconds % (60 * 60 * 24);
            long hour = seconds / (60 * 60);
            if (hour > 0) {
                sb.append(String.format("%d小时", hour));
                if (onlyDisplayLongIfPassed) {
                    return sb.toString();
                }
            }

            seconds = seconds % (60 * 60);
            long min = seconds / 60;
            if (min > 0) {
                sb.append(String.format("%d分钟", min));
                if (onlyDisplayLongIfPassed) {
                    return sb.toString();
                }
            }

        }


        return sb.toString();
    }

    /**
     * 获取日期对象 从格式化字符串中
     */
    public static Date getDateFromFormatString(String date) {

        if (TextUtils.isEmpty(date)) {
            return null;
        }
        String sDate = convertDateToStandardFormat(date);
        Date d = null;
        try {
            if (!TextUtils.isEmpty(sDate)) {
                d = yyyyMMdd().parse(sDate);
            }
        } catch (Exception e) {
        }
        return d;
    }

    /**
     * 格式化成2013-05-13
     */
    public static String formateStringToDate(int year, int month, int day) {
        Calendar c1 = Calendar.getInstance();
        c1.set(year, month, day);
        return yyyy_MM_dd().format(c1.getTime());
    }

    /**
     * 获取2013-12-02 05:30 的总毫秒数
     */
    public static long getTimeInMillisFromDate(String date) {
        Calendar c = Calendar.getInstance();
        Date d;
        long result;
        try {
            d = yyyy_MM_dd_HH_mm().parse(date);
            c.setTime(d);
            result = c.getTimeInMillis();
        } catch (ParseException e) {
            e.printStackTrace();
            result = -1;
        }
        return result;

    }

    /**
     * 计算起点时间与终点时间 的分钟差
     */
    public static int diffTimeMinite(String departTime, String arrivalTime) {
        // 如果arrivalTime 小于departTime 那么arrivalTime 往后加一天;
        if (TextUtils.isEmpty(departTime) || TextUtils.isEmpty(arrivalTime)) {
            return 0;
        }
        try {
            Calendar start = Calendar.getInstance();
            start.set(0, 0, 0, 0, 0, 0);
            Calendar end = Calendar.getInstance();
            end.set(0, 0, 0, 0, 0, 0);

            start.setTime(HH_mm().parse(departTime));
            end.setTime(HH_mm().parse(arrivalTime));

            if (start.after(end)) {
                end.add(Calendar.DAY_OF_MONTH, 1);
                if (start.after(end)) {
                    // 无效时间
                    return 0;
                }
            }
            int result;
            result = (int) ((end.getTimeInMillis() - start.getTimeInMillis()) / 60000);
            return result;
        } catch (Exception e) {
        }
        return 0;
    }

    /*
     * 取消时间格式前面的0 eg:06-6
     */
    public static String trimZero(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        return str.replaceFirst("^(0+)", "");
    }

    /*
     * 日期格式前面补0 eg:6-06
     */
    public static String formatZero(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        if (str.matches("\\d+")) {
            int i = TypeUtils.StringToInt(str);
            str = String.format("%02d", i);
            return str;
        }
        return str;
    }

    /**
     * 2009-10-02 从yyyy_MM_dd 中获取星期几
     */
    public static String getWeekDay(String date) {
        if (TextUtils.isEmpty(date)) {
            return "";
        }
        try {
            Date d = yyyy_MM_dd().parse(date);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return WEEK_CHS2[c.get(Calendar.DAY_OF_WEEK)];
        } catch (ParseException e) {
        }

        return "";
    }

    /**
     * orderTime 是2013-12-13 departTime 是 12月23号
     * <p>
     * 需要返回2013-12-23
     */
    public static String getTicketDepartTime(String orderTime, String departTime) {
        String result = departTime;
        try {
            Date orderDate = yyyy_MM_dd().parse(orderTime);
            Calendar orderCalendar = Calendar.getInstance();
            orderCalendar.setTime(orderDate);

            Date departDate = Md().parse(departTime);
            Calendar departCalendar = Calendar.getInstance();
            departCalendar.setTime(departDate);
            departCalendar.set(Calendar.YEAR, orderCalendar.get(Calendar.YEAR));

            if (departCalendar.before(orderCalendar)) {
                departCalendar.add(Calendar.YEAR, 1);
            }

            result = yyyy_MM_dd().format(departCalendar.getTime());

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 2009年10月02日 转换成 2009-10-02
     */
    public static String getCtoCross(String from) {
        if (TextUtils.isEmpty(from)) {
            return "";
        }
        try {
            Date d = yyyCMMCddC().parse(from);
            return yyyy_MM_dd().format(d);
        } catch (ParseException e) {
        }

        return from;
    }

    public static Date parseYMDHMSDate(String dateStr) {
        try {
            return yyyy_MM_dd_HH_mm_ss().parse(dateStr);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 将HH_mm 转换成分钟
     */
    public static String getTTRuntimeMinites(String runtime) {
        if (TextUtils.isEmpty(runtime)) {
            return "";
        }
        try {
            Date d = HH_mm().parse(runtime);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            int dayofyear = c.get(Calendar.DAY_OF_YEAR);
            int hourofday = c.get(Calendar.HOUR_OF_DAY);
            int minite = c.get(Calendar.MINUTE);

            if ((hourofday > 0 || minite > 0) && dayofyear > 0) {
                dayofyear -= 1;
            }

            return "" + ((dayofyear * 24 + hourofday) * 60 + minite);
        } catch (ParseException e) {
        }

        return runtime;
    }

    /**
     * 返回俩个指点时间的天数差 月份是Calendar的标准month
     */
    public static int getDaysCount(int... datas) {
        if (null == datas || datas.length < 6) {
            return 0;
        }
        try {
            Calendar pre = Calendar.getInstance();
            Calendar next = Calendar.getInstance();
            next.setTime(pre.getTime());
            pre.set(datas[0], datas[1], datas[2]);
            next.set(datas[3], datas[4], datas[5]);
            return (int) ((pre.getTime().getTime() - next.getTime().getTime()) / LONG_TIME_OF_A_DAY);
        } catch (Exception e) {
            return 0;
        }
    }

    public static String getChatTime(String formatTime) {
        Date date;
        try {
            date = yyyy_MM_dd_HH_mm_ss().parse(formatTime);
        } catch (ParseException e) {
            date = new Date();
        }
        Date currentDate = new Date();

        String t;
        if (currentDate.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000L) {
            Calendar f_cal = Calendar.getInstance();
            f_cal.setTime(date);
            int w = f_cal.get(Calendar.DAY_OF_WEEK);

            Calendar c_cal = Calendar.getInstance();
            c_cal.setTime(currentDate);
            int c_w = c_cal.get(Calendar.DAY_OF_WEEK);

            t = (w == c_w ? "" : (WEEK_CHS2[w] + " ")) + HH_mm().format(date);
        } else {
            t = yyyy_MM_dd_HH_mm().format(date);
        }
        return t;
    }

    /**
     * 新版通知中心时间规则from v7.1.1
     * 当天，采用24小时时间制  00:00
     * 前一天，采用 昨天 00:00
     * 前5天，采用 星期几 00:00
     * 大于5天，采用x月x日  00:00
     * 隔年，采用xxxx年x月x日 00:00
     *
     * @param formatTime
     * @return
     */
    public static String getChatTimeV2(String formatTime) {
        String chatTimeInfo = "";
        Date chatDate;
        try {
            chatDate = yyyy_MM_dd_HH_mm_ss_SSS().parse(formatTime);
        } catch (ParseException e) {
            chatDate = new Date();
        }
        Calendar chatCalendar = Calendar.getInstance();
        chatCalendar.setTime(chatDate);
        Date currentDate = new Date();
        Calendar currentCalendar = Calendar.getInstance();
        currentCalendar.setTime(currentDate);
        if (chatCalendar.get(Calendar.YEAR) != currentCalendar.get(Calendar.YEAR)) {
            //跨年
            chatTimeInfo = yyyCMMCddCHH_MM().format(chatDate);
        } else {
            if (isAmongDayOfOffset(chatDate.getTime(), 0)) {
                //当天
                chatTimeInfo = HH_mm().format(chatDate);
            } else if (isAmongDayOfOffset(chatDate.getTime(), -1)) {
                //跨天
                chatTimeInfo = "昨天 " + HH_mm().format(chatDate);
            } else if (isAmongDayOfOffset(chatDate.getTime(), -5)) {
                //星期的显示格式
                int chatDayOfWeek = chatCalendar.get(Calendar.DAY_OF_WEEK);
                chatTimeInfo = WEEK_CHS2[chatDayOfWeek] + " " + HH_mm().format(chatDate);
            } else {
                //同年
                chatTimeInfo = MdHm().format(chatDate);
            }
        }


        return chatTimeInfo;
    }


    /**
     * 判断时间是否在offset时间范围之内
     * -6:前6天
     * -1：昨天
     * 0：今天
     *
     * @param timellis
     * @return
     */
    private static boolean isAmongDayOfOffset(long timellis, int offset) {
        Calendar c = Calendar.getInstance();
        clearCalendar(c, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND);
        c.add(Calendar.DAY_OF_MONTH, offset);
        long firstOfDay = c.getTimeInMillis(); // offset最早时间

        c.setTimeInMillis(timellis);
        clearCalendar(c, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND); // 指定时间戳当天最早时间

        return firstOfDay <= c.getTimeInMillis();

    }

    private static void clearCalendar(Calendar c, int... fields) {
        for (int f : fields) {
            c.set(f, 0);
        }
    }


    public static String formateToYMD(long time) {
        Date date = new Date(time);
        return yyyyMMdd().format(date);
    }

    public static String getMonth(String date, String defaultValue) {
        if (TextUtils.isEmpty(date)) {
            return defaultValue;
        }
        String sDate = convertDateToStandardFormat(date);
        try {
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return "" + (c.get(Calendar.MONTH) + 1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return defaultValue;
    }

    public static String getDay(String date, String defaultValue) {
        if (TextUtils.isEmpty(date)) {
            return defaultValue;
        }
        String sDate = convertDateToStandardFormat(date);
        try {
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            int day = c.get(Calendar.DAY_OF_MONTH);
            if (day < 10) {
                return "0" + day;
            }
            return "" + day;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return defaultValue;
    }

    public static String getCurrentHHmm() {
        return HH_mm().format(new Date());
    }

    /**
     * 20091002 转换成 2009-10-02
     */
    public static String getDashDate(String from) {
        if (TextUtils.isEmpty(from)) {
            return "";
        }

        try {
            from = convertDateToStandardFormat(from);
            Date d = yyyyMMdd().parse(from);
            return yyyy_MM_dd().format(d);
        } catch (ParseException e) {
            from = "";
        }

        return from;
    }

    /**
     * 将HH_mm 转换成分钟
     */
    public static int getRuntimeMinites(String runtime) {
        if (TextUtils.isEmpty(runtime)) {
            return -1;
        }
        try {
            Date d = HH_mm().parse(runtime);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            int dayofyear = c.get(Calendar.DAY_OF_YEAR);
            int hourofday = c.get(Calendar.HOUR_OF_DAY);
            int minite = c.get(Calendar.MINUTE);

            if ((hourofday > 0 || minite > 0) && dayofyear > 0) {
                dayofyear -= 1;
            }

            return ((dayofyear * 24 + hourofday) * 60 + minite);
        } catch (ParseException e) {
        }

        return -1;
    }

    /**
     * 根据日期来获取年月日等
     */
    public static int getDateValue(String date, int type) {
        if (TextUtils.isEmpty(date)) {
            return -1;
        }
        try {
            Date d = yyyy_MM_dd().parse(date);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return c.get(type);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return -1;
    }

    public static long getDateMillon(String date, String time) {
        String dateTime = date + " " + time;
        try {
            Date d = yyyy_MM_dd_HH_mm().parse(dateTime);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long getTomorrowMillon(long dateTime) {
        Date d = new Date(dateTime);
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.DAY_OF_MONTH, 1);
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime().getTime();
    }

    public static String getDiffDate(long currentBeginTime, int diff) {
        // 查找俩天前的行程
        String beginDay = "";
        try {
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(currentBeginTime);
            c.add(Calendar.DAY_OF_YEAR, diff);
            beginDay = yyyy_MM_dd().format(c.getTime());
        } catch (Exception e) {
            // ignore
        }
        return beginDay;
    }

    public static String getNoramlFormateDate(long currentBeginTime) {
        // 查找俩天前的行程
        String beginDay = "";
        try {
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(currentBeginTime);
            beginDay = yyyy_MM_dd().format(c.getTime());
        } catch (Exception e) {
            // ignore
        }
        return beginDay;
    }

    /**
     * 获取现在时间
     *
     * @param hour 减小的时间
     * @return
     */
    public static String getStringDateShort(int hour) {
        Date currentTime = new Date();
        Calendar c1 = Calendar.getInstance();
        c1.setTime(currentTime);
        c1.add(Calendar.HOUR_OF_DAY, hour);
        String dateString = yyyy_MM_dd().format(c1.getTime());
        return dateString;
    }

    public static String getNoramlFormateTime(long currentBeginTime, int hour) {
        // 查找俩天前的行程
        String beginTime = "";
        try {
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(currentBeginTime);
            c.add(Calendar.HOUR_OF_DAY, hour);
            beginTime = HH_mm().format(c.getTime());
        } catch (Exception e) {
            // ignore
        }
        return beginTime;
    }

    public static long getDateMillon(String date, String time, int dayDiff) {
        String dateTime = date + " " + time;
        try {
            Date d = yyyy_MM_dd_HH_mm().parse(dateTime);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            c.add(Calendar.DAY_OF_YEAR, dayDiff);
            return c.getTime().getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static String addDays(String day, int diff, String defaultValue) {
        String result = defaultValue;
        ;
        if (TextUtils.isEmpty(day)) {
            return result;
        }

        try {
            Date d = yyyy_MM_dd().parse(day);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            c.add(Calendar.DAY_OF_YEAR, diff);
            result = yyyy_MM_dd().format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public static String addDays(String day, int diff) {
        String result = day;
        ;
        if (TextUtils.isEmpty(day)) {
            return day;
        }

        try {
            Date d = yyyy_MM_dd().parse(day);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            c.add(Calendar.DAY_OF_YEAR, diff);
            result = yyyy_MM_dd().format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public static String addHour(String hour, int diff) {
        String result = hour;
        if (TextUtils.isEmpty(hour)) {
            return result;
        }
        try {
            Date d = HH_mm().parse(hour);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            // c.set(Calendar.YEAR, 2013);
            c.add(Calendar.HOUR_OF_DAY, diff);
            result = HH_mm().format(c.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return result;
    }

    public static String getTimeTableMsgTime(String timeDate) {
        if (!TextUtils.isEmpty(timeDate)) {

            try {
                Date d = yyyy_MM_dd_HH_mm_ss_SSS().parse(timeDate);
                Calendar c = Calendar.getInstance();
                c.setTime(d);
                String result = String.format("%s %s", yyyy_MM_dd().format(d), HH_mm_C().format(d));
                return result;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return "";
    }

    public static String getTimeTableMsgTime2(String timeDate) {
        if (!TextUtils.isEmpty(timeDate)) {

            try {
                Date d = yyyy_MM_dd_HH_mm_ss_SSS().parse(timeDate);
                Calendar c = Calendar.getInstance();
                c.setTime(d);
                String result = String.format("%s %s", MM_dd().format(d), HH_mm().format(d));
                return result;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        return "";
    }

    /**
     * 时间的月日是否在有效期内
     *
     * @param date 2014-02-02
     * @param from 12-01
     * @param to   03-31
     * @return
     */
    public static boolean isDateBetweenFromTo(String date, String from, String to) {
        try {
            Date d = getDateFromFormatString(date);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            int year = c.get(Calendar.YEAR);

            date = yyyy_MM_dd().format(d);

            if (from.compareTo(to) >= 0) {
                String fromEarly = String.format("%s-%s", year - 1, from);
                String toEarly = String.format("%s-%s", year, to);
                String fromLater = String.format("%s-%s", year, from);
                String toLater = String.format("%s-%s", year + 1, to);
                return (fromEarly.compareTo(date) <= 0 && toEarly.compareTo(date) >= 0) || (fromLater.compareTo(date) <= 0 && toLater.compareTo(date) >= 0);
            } else {
                String fromMiddle = String.format("%s-%s", year, from);
                String toMiddle = String.format("%s-%s", year, to);
                return fromMiddle.compareTo(date) <= 0 && toMiddle.compareTo(date) >= 0;
            }

        } catch (Exception e) {
            return true;
        }
    }

    /**
     * 将yyyy-MM-dd格式的日期字符串 转换成"2012年9月11日 星期三"的格式
     *
     * @return
     */
    public static String convertDateStringToYearMouthDayWeek(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String ymd = yyyCMMCddC().format(d);
            String week = getWeekDayChsOfTheDate(sDate);
            return ymd + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 将 yyyyMMdd 或 yyyy-MM-dd 格式的日期字符串转化成"周几"的中文
     *
     * @param date 日期字符串
     */
    public static String getWeekDayChsOfTheDate(String date) {
        return getWeekDayChsOfTheDate(date, WEEKDAY_TYPE_TWO_WORDS);
    }

    /**
     * 将 yyyyMMdd 或 yyyy-MM-dd 格式的日期字符串转化成周几或星期几的中文
     *
     * @param date 日期字符串
     * @param type 转化成2个字的中文还是3个字的中文
     */
    public static String getWeekDayChsOfTheDate(String date, int type) {
        String weekdayChs = "";
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);

            int iweek = c.get(Calendar.DAY_OF_WEEK);
            switch (type) {
                case WEEKDAY_TYPE_TWO_WORDS:
                    weekdayChs = WEEK_CHS[iweek];
                    break;
                case WEEKDAY_TYPE_THREE_WORDS:
                    weekdayChs = WEEK_CHS2[iweek];
                    break;
            }
        } catch (Exception e) {
        }

        return weekdayChs;
    }

    /*
     * 将2011-1-11 转换成：1月11日 周三
     */
    public static String getSimpleMDWString(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date dateO = yyyyMMdd().parse(sDate);
            String md = Md().format(dateO);
            String week = getWeekDayChsOfTheDate(date, WEEKDAY_TYPE_TWO_WORDS);
            return md + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return date;
    }

    /*
     * 将2011-1-11 转换成：2011年1月11日 周三
     */
    public static String getSimpleYMDWString(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date dateO = yyyyMMdd().parse(sDate);
            String ymd = yyyCMMCddC().format(dateO);
            String week = getWeekDayChsOfTheDate(date, WEEKDAY_TYPE_TWO_WORDS);
            return ymd + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return date;
    }

    /*
     * 将Long转换成String
     */
    public static String convertLongToString(long time) {
        try {
            Date date = new Date();
            date.setTime(time);
            return yyyy_MM_dd_HH_mm().format(date);
        } catch (Exception e) {
            return "";
        }
    }

    /*
     * Date类型对应字段添加对应值
     */
    public static Date getDateAddByField(Date date, int field, int value) {
        try {
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(field, value);
            return c.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return date;
    }

    public static long getTimeAfterDays(long startTime, int days) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        cal.setTimeInMillis(startTime);
        cal.add(Calendar.DATE, days);
        return cal.getTimeInMillis();
    }

    public static long getTimeTomorow() {
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("GMT"));
        cal.add(Calendar.DATE, 1);
        return cal.getTimeInMillis();
    }

    public static Date getDate(String srcStr, String srcFormat) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(srcFormat, Locale.getDefault());
            return sdf.parse(srcStr);
        } catch (Exception ex) {

        }
        return null;
    }

    public static Date getDateAfterDays(Date startDate, int days) {
        if (startDate == null) {
            return null;
        }
        long time = getTimeAfterDays(startDate.getTime(), days);
        Date date = new Date(time);
        return date;
    }

    public static String getDateStr(long date, String format) {
        try {
            DateFormat df = new SimpleDateFormat(format, Locale.getDefault());
            df.setTimeZone(TimeZone.getTimeZone("GMT"));
            return df.format(date);
        } catch (Exception ex) {

        }
        return null;
    }

    public static String getYMDHMCStringByServerDateTime(String datetime) {
        if (TextUtils.isEmpty(datetime)) {
            return "";
        }

        try {
            Date d = yyyy_MM_dd_HH_mm_ss_S().parse(datetime);
            return yyyCMMCddCHH_MM().format(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    public static String getYMDHMCStringByDateTime(String datetime) {
        if (TextUtils.isEmpty(datetime)) {
            return "";
        }

        try {
            Date d = yyyy_MM_dd_HH_mm_ss().parse(datetime);
            return yyyCMMCddCHH_MM().format(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    public static String getYMDStringByDateTime(String datetime) {
        if (TextUtils.isEmpty(datetime)) {
            return "";
        }

        try {
            Date d = yyyy_MM_dd_HH_mm_ss().parse(datetime);
            return yyyy_MM_dd().format(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return "";
    }

    public static long getDays(boolean abs, long date0, long date1) {
        if (abs) {
            return Math.abs(date1 - date0) / 86400000L;
        }
        return (date1 - date0) / 86400000L;
    }

    public static long getDateTimeFirstInMonth(int year, int month) {
        Calendar calen = Calendar.getInstance();
        calen.setTimeZone(TimeZone.getTimeZone("GMT"));
        calen.set(year, month, 1);
        return calen.getTimeInMillis();
    }

    /**
     * 毫秒d1 和 d2 之间间隔的天数
     */
    public static int manyDaysBetweenTwoDays(long d1, long d2) {
        int result = -1;
        //每天的凌晨时间
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(d1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        Calendar current = Calendar.getInstance();
        current.setTimeInMillis(d2);
        current.set(Calendar.HOUR_OF_DAY, 0);
        current.set(Calendar.MINUTE, 0);
        current.set(Calendar.SECOND, 0);
        current.set(Calendar.MILLISECOND, 0);

        result = (int) ((current.getTime().getTime() - calendar.getTime().getTime()) / LONG_TIME_OF_A_DAY);
        return result;
    }

    /**
     * 20091002 ,2009-10-02,转换成毫秒
     */
    public static long getDashDateInMillis(String from) {
        long result = -1;
        if (TextUtils.isEmpty(from)) {
            return result;
        }
        try {
            Date d = null;
            if (from.contains("-")) {
                d = yyyy_MM_dd().parse(from);
            } else {
                d = yyyyMMdd().parse(from);
            }
            if (d != null) {
                result = d.getTime();
            }
            return result;
        } catch (ParseException e) {
            result = -1;
        }

        return result;
    }

    /**
     * 2009-10-02/20090202 从yyyy_MM_dd 中获取星期几
     */
    public static String getWeekDayFromDate(String date) {
        if (TextUtils.isEmpty(date)) {
            return "";
        }
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(d);
            return WEEK_CHS2[c.get(Calendar.DAY_OF_WEEK)];
        } catch (ParseException e) {
        }

        return "";
    }


    /*
     * 将yyy-MM-dd格式的日期字符串转成"9月11日 星期三"的格式
     */
    public static String getYMDWString3(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            String ymd = Md().format(d);
            String week = getDayInWeek(sDate);
            return ymd + " " + week;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /*
     * 将xx-xx格式的日期字符串转成"09月11日"的格式
     */
    public static String convertMM_ddToMd(String mm_dd) {
        try {
            Date d = MM_dd().parse(mm_dd);
            return Md().format(d);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return mm_dd;
    }

    public static long getYMDStringLongTime(String date) {
        try {
            if (TextUtils.isEmpty(date)) {
                return 0;
            }
            String sDate = convertDateToStandardFormat(date);
            Date mDate = yyyyMMdd().parse(sDate);
            Calendar c = Calendar.getInstance();
            c.setTime(mDate);
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);

            return c.getTimeInMillis();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 到达日期为23：58出发日期为00：03这种车次，服务器返回的arriveDate不能直接用
     *
     * @param arriveDate
     * @param departTime
     * @param arriveTime
     * @return
     */
    public static String getDepartDateByArriveDate(String arriveDate, String departTime, String arriveTime) {
        if (TextUtils.isEmpty(departTime) || TextUtils.isEmpty(arriveTime)) {
            return arriveDate;
        }

        if (departTime.compareTo(arriveTime) > 0 || TextUtils.isEmpty(arriveDate)) {
            return arriveDate;
        }

        if (arriveDate.contains("-") && arriveDate.length() == 10) {
            try {
                return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(
                        new Date(new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(arriveDate).getTime() + TimeUnit.DAYS.toMillis(1))
                );
            } catch (ParseException e) {
                return arriveDate;
            }
        } else if (arriveDate.length() == 8) {
            try {
                return new SimpleDateFormat("yyyyMMdd", Locale.CHINA).format(
                        new Date(new SimpleDateFormat("yyyyMMdd", Locale.CHINA).parse(arriveDate).getTime() + TimeUnit.DAYS.toMillis(1))
                );
            } catch (ParseException e) {
                return arriveDate;
            }
        } else {
            return arriveDate;
        }


    }

    public static int getDaysInMonth(int month, int year) {
        switch (month) {
            case Calendar.JANUARY:
            case Calendar.MARCH:
            case Calendar.MAY:
            case Calendar.JULY:
            case Calendar.AUGUST:
            case Calendar.OCTOBER:
            case Calendar.DECEMBER:
                return 31;
            case Calendar.APRIL:
            case Calendar.JUNE:
            case Calendar.SEPTEMBER:
            case Calendar.NOVEMBER:
                return 30;
            case Calendar.FEBRUARY:
                return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
            default:
                throw new IllegalArgumentException("Invalid Month");
        }
    }

    /**
     * 火车票搜索控件的日期显示
     *
     * @param year
     * @param month
     * @param day
     * @return
     */
    public static String[] getDayInWeekDayMonthForSearchView(int year, int month, int day) {
        String[] dateInSplite = new String[4]; // 星期、几号、月份,是否要显示 今天/明天/后天/节假日
        Calendar c = Calendar.getInstance();
        String today = yyyyMMdd().format(c.getTime());
        c.add(Calendar.DATE, 1);
        String tommorrow = yyyyMMdd().format(c.getTime());
        c.add(Calendar.DATE, 1);
        String theDayAfterTommorrow = yyyyMMdd().format(c.getTime());
        c.set(year, month, day);
        dateInSplite[0] = getDayInWeek(yyyyMMdd().format(c.getTime()));
        String mixHoliday = GTLunarCalendarV2.getMixHoliday(year, month + 1, day);
        String strFromConfig = getLunarFromConfig(year, month + 1, day);
        boolean showHoliday = true;
        if (!TextUtils.isEmpty(mixHoliday)) {
            dateInSplite[0] = mixHoliday;
        } else if (!TextUtils.isEmpty(strFromConfig)) {
            dateInSplite[0] = strFromConfig;
        } else if (today.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "今天";
        } else if (tommorrow.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "明天";
        } else if (theDayAfterTommorrow.equals(yyyyMMdd().format(c.getTime()))) {
            dateInSplite[0] = "后天";
        } else {
            showHoliday = false;
        }

        dateInSplite[1] = c.get(Calendar.DAY_OF_MONTH) < 10 ? "0" + c.get(Calendar.DAY_OF_MONTH) : "" + c.get(Calendar.DAY_OF_MONTH);
        dateInSplite[2] = (c.get(Calendar.MONTH) + 1) < 10 ? "0" + (c.get(Calendar.MONTH) + 1) : "" + (c.get(Calendar.MONTH) + 1);
        dateInSplite[3] = showHoliday ? "1" : "0";
        return dateInSplite;
    }

    /**
     * 南方小年，北方小年
     *
     * @param year
     * @param month
     * @param day
     * @return
     */

    public static String getLunarFromConfig(int year, int month, int day) {
        String result = "";
//        if (TicketConfigManager.getInstance().getModel().getLunars() != null && TicketConfigManager.getInstance().getModel().getLunars().size() > 0) {
//            List<String> lunars = TicketConfigManager.getInstance().getModel().getLunars();
//            String string_year = "";
//            String string_month = "";
//            String string_day = "";
//
//            string_year = year + "";
//            if (month < 10) {
//                string_month = "0" + month;
//            } else {
//                string_month = month + "";
//            }
//
//            if (day < 10) {
//                string_day = "0" + day;
//            } else {
//                string_day = day + "";
//            }
//            if (!TextUtils.isEmpty(string_year) && !TextUtils.isEmpty(string_month) && !TextUtils.isEmpty(string_day)) {
//                String target = string_year + string_month + string_day;
//                for (int i = 0; i < lunars.size(); i++) {
//                    String item = lunars.get(i);
//                    if (item.contains(target)) {
//                        String[] arrs = item.split(",");
//                        if (arrs != null && arrs.length == 2) {
//                            result = arrs[1];
//                        }
//                    }
//                }
//            }
//
//        }
        return result;
    }

    /*
     * 本年为M月d日，往年为yyyy年M月d日
     */
    public static String getMdYearNeeded(String date) {
        try {
            String sDate = convertDateToStandardFormat(date);
            Date d = yyyyMMdd().parse(sDate);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(d);
            if (calendar.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR)) {
                return Md().format(d);
            }
            return yyyCMMCddC().format(d);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

}

